#!/bin/bash

if [ -f ./func.sh ]; then
  source ./func.sh
elif [ -f scripts/func.sh ]; then
  source scripts/func.sh
fi

NEW_ORG_DIR=/tmp/org2

rm -rf ${NEW_ORG_DIR}/crypto-config
rm -rf ${NEW_ORG_DIR}/org2.json
rm -rf /etc/hyperledger/fabric/crypto-config/peerOrganizations/org2.example.com

export FABRIC_CFG_PATH=${NEW_ORG_DIR}

cryptogen generate \
  --config=${NEW_ORG_DIR}/crypto-config.yaml \
  --output=${NEW_ORG_DIR}/crypto-config

configtxgen -printOrg Org2MSP > ${NEW_ORG_DIR}/org2.json


cp -r \
  ${NEW_ORG_DIR}/crypto-config/peerOrganizations/org2.example.com \
  /etc/hyperledger/fabric/crypto-config/peerOrganizations/org2.example.com